package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.OrderMapper;
import com.itheima.health.mapper.OrderSettingMapper;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.date.DateUtils;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.RedisMessageConstant;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
@Transactional
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Override
    public Order add(Map map) {
        //  1. 判断验证码是否正确 或 过期
        String codeFromMap = (String) map.get("validateCode");
        String telephone = (String) map.get("telephone");
        String redisCode = RedisUtil.get(RedisMessageConstant.SENDTYPE_ORDER + telephone);
        if(StringUtils.isBlank(redisCode)){
            //  过期
            throw  new RuntimeException("验证码过期");
        }
        if(StringUtils.isBlank(codeFromMap)){
            //  表单验证码null
            throw  new RuntimeException("验证码必须填写");
        }
        if(!redisCode.equals(codeFromMap)){
            //  验证码错误
            throw  new RuntimeException("验证码错误");
        }
        return null;
    }

    @Override
    public Map findOrderDetailByOrderId(int id) {
        return null;
    }
}
